package com.ship.boats.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ship.boats.domain.SpBoatsShipCount;
import com.ship.boats.mapper.BoatsShipCountMapper;
import com.ship.boats.service.BoatsShipCountService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <b>BoatsShipCountServiceImpl</b>
 *
 * @description: BoatsShipCountServiceImpl <br>
 * @date: 2024/6/3 11:06 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class BoatsShipCountServiceImpl extends ServiceImpl<BoatsShipCountMapper, SpBoatsShipCount> implements BoatsShipCountService {
    @Override
    public void createShipCount(Integer countTotal) {
        String date = DateUtil.format(new Date(), DatePattern.NORM_DATE_FORMATTER);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("create_date",date);
        SpBoatsShipCount spBoatsShipCount = baseMapper.selectOne(queryWrapper);
        if (null != spBoatsShipCount){
            spBoatsShipCount.setCountNumber(countTotal);
            baseMapper.updateById(spBoatsShipCount);
        }else {
            SpBoatsShipCount spBoatsShipCount1 = new SpBoatsShipCount();
            spBoatsShipCount1.setCreateDate(new Date());
            spBoatsShipCount1.setCountNumber(countTotal);
            baseMapper.insert(spBoatsShipCount1);
        }
    }
}
